package com.atguigu.gmall.list.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.list.Service.SearchService;
import com.atguigu.gmall.model.list.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/list")
public class ListApiController {
    @Autowired
    private ElasticsearchRestTemplate restTemplate;
    @Autowired
    private SearchService searchService;


    @GetMapping("inner/createIndex")
    public Result createIndex() {
        //创建索引库和mapping映射
        restTemplate.createIndex(Goods.class);
        restTemplate.putMapping(Goods.class);
        //返回
        return Result.ok();
    }

    @GetMapping("incrHotScore")
    public Result incrHotScore(Long skuId){
        searchService.incrHotScore(skuId);
        return Result.ok();

    }

}
